package com.atwulidun.command13;

public class CommandDemo {
    public static void main(String[] args) {
        // 创建一个LightReceiver
        LightReceiver lightReceiver = new LightReceiver();
        // 创建一个TVReceiver
        TVReceiver tvReceiver = new TVReceiver();
        // 创建电灯对应的开关命令对象
        LightOnCommand lightOnCommand = new LightOnCommand(lightReceiver);
        LightOffCommand lightOffCommand = new LightOffCommand(lightReceiver);
        // 创建电视对应的开关命令对象
        TVOnCommand tvOnCommand = new TVOnCommand(tvReceiver);
        TVOffCommand tvOffCommand = new TVOffCommand(tvReceiver);
        // 创建一个遥控器对象
        RemoteController remoteController = new RemoteController();
        // 将电灯对应的命令设置到遥控器的第一行
        remoteController.setCommands(0, lightOnCommand, lightOffCommand);
        // 将电视对应的命令设置到遥控器的第二行
        remoteController.setCommands(1, tvOnCommand, tvOffCommand);
        // 下面对电灯发送命令
        System.out.println("对电灯进行遥控：");
        // 打开电灯
        remoteController.onButtonIsPushed(0);
        // 关闭电灯
        remoteController.offButtonIsPushed(0);
        // 对关闭电灯操作进行撤销
        remoteController.undo();
        // 下面对电视发送命令
        System.out.println("对电视进行遥控");
        // 打开电视
        remoteController.onButtonIsPushed(1);
        // 关闭电视
        remoteController.offButtonIsPushed(1);
        // 对关闭电视操作进行撤销
        remoteController.undo();
    }
}
